{% extends 'InterArticleBundle::layout.admin.html.twig' %}

{% block header_title %}
USER
{% endblock %}

{% block css_script %}
<style>
.sortable {color:white;}
</style>
{% endblock %}

{% block content %}	
	<!-- Full width table -->
	<div class="col-lg-12">
		
		<div class="module no-padding">
 			<div class="module-header"><h4>LIST</h4></div>
			<div class="module-content table-responsive">
				<table class="table table-striped">
					<thead>
						<tr>
							<th>ID</th>
							<th>UserName</th>
 							<th>Email</th>
 							<th>Role</th>
							<th class="text-right">Actions</th>
						</tr>
					</thead>
					<tbody>
						<tr>							
							{% for user in users %}
								<tr {% if loop.index is odd %}class="color"{% endif %}>
								    <td>{{ user.id }}</td>
								    <td>{{ user.UserName }}</td>
								    <td>{{ user.Email }}</td>
								    <td id="user_role_{{ user.id }}">{{ user.Roles[0] }}</td>		
								    
								    <td class="text-right">
									{% if user.Roles[0] == 'ROLE_USER' %}
								    	<button id="role_change_{{ user.id }}" class="btn btn-xs btn btn-grape" onclick="listUser.changeRole({{ user.id }},2)">
								    		{{ 'change Role To ADMIN' }}
								    	</button>
								    {% elseif user.Roles[0] == 'ROLE_ADMIN'  %}
								    	<button id="role_change_{{ user.id }}" class="btn btn-xs btn btn-grape" onclick="listUser.changeRole({{ user.id }},1)">
								    		{{ 'change Role To USER' }}
								    	</button>
								    {% endif %}
								    </td>
								</tr>
							{% else %}
								<tr><td colspan="2"><p>There are no article entries for symblog</p></td></tr>
							{% endfor %}
							
							
							
						</tr>
						
					</tbody>
				</table>				
			</div>			
		</div>
	</div>
	
	
{% endblock %}

{% block js_script %}


<script>
var listUser = {
		demo: function(a) {
			alert(a);
		},
	    
		changeRole:function(x,y){
			$.ajax({
		        type: "POST",
		        url: "{{ url('inter_article_admin_user_change_role') }}",
		        data: {
		           id: x,
		            r: y
		        },
		        dataType: "json",
		        success: function(response) {
		            //console.log(response);
		            
		            //alert(response.role);
		            $('#user_role_'+response.id).html(response.role);
		            if(response.role == 'ROLE_ADMIN'){
						$('#role_change_'+response.id).html('change Role To USER');
						$('#role_change_'+response.id).attr('onclick','listUser.changeRole('+response.id+',1)');
				    } else {
				    	$('#role_change_'+response.id).html('change Role To ADMIN');
				    	$('#role_change_'+response.id).attr('onclick','listUser.changeRole('+response.id+',2)');			    	
					}
		        }
		    });
		}
	    
	};

</script>


{% endblock %}









